<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <el-card style="margin-top: 10px">
      <el-button type="primary" class="btn-tian">添加商品</el-button>
        
      <!-- 表格 -->
      <el-table
        :data="tableData1"
        style="width: 100%"
        row-key="cat_id"
        border
        lazy
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column type="index" label="#" width="180"> </el-table-column>
        <el-table-column prop="cat_name" label="分类名称" width="180"> </el-table-column>
        <el-table-column prop="cat_deleted" label="是否有效" width="360">
            <template slot-scope="scope">
            <el-button type="success" icon="el-icon-check" circle size="mini"></el-button>
            </template>
        </el-table-column>
        <el-table-column prop="cat_level" label="排序" width="360">
          <template slot-scope="scope">
            <el-tag v-if='scope.row.cat_level==0' effect='dark'>一级</el-tag>
            <el-tag v-if='scope.row.cat_level==1' type="success" effect='dark'>二级</el-tag>
            <el-tag v-if='scope.row.cat_level==2' type="info" effect='dark'>三级</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="360"> 
             <template slot-scope="scope">
                 <el-button type="primary" icon="el-icon-edit" size="mini">编辑</el-button>
                 <el-button type="danger" icon="el-icon-delete" size="mini">删除</el-button>
             </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData1: [],

      pagenum: 1,
      pagesize: 4,
    };
  },
  mounted() {
    this.getdata();
  },
  methods: {
    getdata() {
      this.$axios
        .get("categories", {
          params: {
            pagenum: this.pagenum,
            pagesize: this.pagesize,
          },
        })
        .then((res) => {
          console.log(res, 720);
          if (res.meta.status == 200) {
            this.tableData1 = res.data.result;
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
.btn-tian{
    margin-bottom: 10px;
}
</style>
